var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/regenerator")), e = require("../../@babel/runtime/helpers/toConsumableArray"), a = require("../../@babel/runtime/helpers/asyncToGenerator"), r = getApp(), o = require("../../http/productApi.js");

Page({
    data: {
        systemInfo: r.data.systemInfo,
        productList: [],
        hasMore: !0,
        loadingMore: !1
    },
    onLoad: function(t) {
        this.couponId = t.couponId, this.waterFallView = this.selectComponent("#waterFallView"), 
        this.loadProductList(!0);
    },
    scrollOnBottom: function() {
        this.loadProductList(!1);
    },
    loadProductList: function(r) {
        var n = this;
        return a(t.default.mark(function a() {
            var i, s, u;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    if (r && (n.setData({
                        productList: [],
                        hasMore: !0
                    }), n.waterFallView.initData(null, null)), n.data.hasMore && !n.data.loadingMore) {
                        t.next = 3;
                        break;
                    }
                    return t.abrupt("return");

                  case 3:
                    return 20, i = n.data.productList.length / 20 + 1, n.setData({
                        loadingMore: !0
                    }), t.prev = 6, t.next = 9, o.couponProductList(i, 20, {
                        couponId: n.couponId
                    });

                  case 9:
                    s = t.sent, u = [].concat(e(n.data.productList), e(s.data.list)), n.setData({
                        inited: !0,
                        productList: u,
                        hasMore: s.data.totalPage > s.data.currPage
                    }), 1 == s.data.currPage ? n.waterFallView.initData(null, s.data.list) : n.waterFallView.appendProducts(s.data.list), 
                    t.next = 18;
                    break;

                  case 15:
                    t.prev = 15, t.t0 = t.catch(6), console.log(t.t0);

                  case 18:
                    return t.prev = 18, n.setData({
                        loadingMore: !1
                    }), t.finish(18);

                  case 21:
                  case "end":
                    return t.stop();
                }
            }, a, null, [ [ 6, 15, 18, 21 ] ]);
        }))();
    }
});